package com.cq.base.utils

import android.app.Activity
import android.content.Context
import android.util.DisplayMetrics
import android.view.View

/**
 * 作者: CQ
 * 日期: 2021-08-03
 * 说明:
 */
// 判断点是否在view中
fun View.isTouchPointInView(x : Int, y : Int) : Boolean {
    val location = IntArray(2)
    getLocationOnScreen(location)
    val left = location[0]
    val top = location[1]
    val right = left + measuredWidth
    val bottom = top + measuredHeight
    return x in left .. right && y in top .. bottom
}

fun Any.getWidth(activity : Context) : Int {
    val dm = DisplayMetrics()
    (activity as Activity).windowManager.defaultDisplay.getMetrics(dm)
    return dm.widthPixels
}

fun Any.getWidth(activity : Activity) : Int {
    val dm = DisplayMetrics()
    activity.windowManager.defaultDisplay.getMetrics(dm)
    return dm.widthPixels
}